#!/bin/bash
#备份目录
BACKUP_DIR=/opt/backup/mysql

#备份文件名
BACKUP_NAME=huijingu-`date +%Y%m%d%H%M`.sql

#进入备份目录
mkdir -p $BACKUP_DIR
cd $BACKUP_DIR

#备份数据库
mysqldump -h localhost -uroot -p!QAZ2wsx@023 huijingu > ${BACKUP_DIR}/${BACKUP_NAME}

#删除30天以前的备份
find ${BACKUP_DIR} -mtime +30 -name "huijingu-20*.sql" -exec rm -rf {} \;
